package com.example.expinterview.controller;

import com.example.expinterview.dto.IntegralDto;
import com.example.expinterview.entity.ResultBody;
import com.example.expinterview.service.IEiListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
  * @classname: Li
  * @description: TODO
  * @author: kaiser
  * @date: 2021/10/20 16:11
  * @version: 1.0
  */
@RestController
@RequestMapping("/integral")
@Api(tags = "积分明细")
public class ListController {
    private final IEiListService service;

    @Autowired
    public ListController(IEiListService service) {
        this.service = service;
    }

    @PostMapping("/save")
    @ApiOperation(value = "创建积分明细 type为true为增加 false为减少")
    public ResultBody save(@RequestBody IntegralDto integral) {
        return service.create(integral);
    }

    @GetMapping("/getById/{id}")
    @ApiOperation(value = "根据id获取")
    public ResultBody getById(@PathVariable Long id) {
        return ResultBody.success(service.getById(id));
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除")
    public ResultBody delete(@PathVariable Long id) {
        return ResultBody.status(service.removeById(id));
    }

    @GetMapping("/list/{userId}")
    @ApiOperation(value = "根据用户id获取积分明细")
    public ResultBody list(@PathVariable Long userId) {
        return service.listById(userId);
    }
}
